package com.warmheart.core.rs.oper;

import com.warmheart.core.cors.builder.CoRsBuilder;
import com.warmheart.core.rs.builder.RsBuilder;
import com.warmheart.core.rs.enums.FieldTypeEnum;
import com.warmheart.core.rs.model.SelectedModel;

/**
 * 
 * @ClassName: Rs
 * @Description: 该类用作对特殊返回值进行处理
 * @author ZhangJianyang
 * @date 2025-06-16 09:37:02
 *
 * @param <T>
 * @param <E>
 */
public class Rs<T extends CoRsBuilder<?, ?>, E extends RsBuilder<T>> {

    private final E e;

    private final T t;

    private final String field;

    private final String prop;

    public Rs(E e, String field, String prop) {
        this.e = e;
        this.t = this.e.core();
        this.field = field;
        this.prop = prop;
    }

    public String fetchField() {
        return this.field;
    }

    public String fetchProp() {
        return this.prop;
    }

    /**
     * 
     * @Title: single
     * @Description: 单字段查询设置
     * @author ZhangJianyang
     * @return
     */
    public T single() {
        this.t.getSelectedModelList().clear();
        this.t.getSelectedModelList().add(new SelectedModel(FieldTypeEnum.SINGLE, this.field, this.prop));
        return this.t;
    }

    /**
     * 
     * @Title: first
     * @Description: 多字段查询首字段添加
     * @author ZhangJianyang
     * @return
     */
    public MultipleOper<T, E> first() {
        this.t.getSelectedModelList().clear();
        this.t.getSelectedModelList().add(new SelectedModel(FieldTypeEnum.MULTIPLE_FIRST, this.field, this.prop));
        return new MultipleOper<T, E>(this.e);
    }

    /**
     * 
     * @Title: group
     * @Description: 分组字段设置
     * @author ZhangJianyang
     * @return
     */
    public GroupCntOper<T, E> group() {
        this.t.getSelectedModelList().clear();
        this.t.getSelectedModelList().add(new SelectedModel(FieldTypeEnum.GROUP, this.field, this.prop));
        return new GroupCntOper<T, E>(this.e);
    }

    /**
     * 
     * @Title: key
     * @Description: KEY字段设置
     * @author ZhangJianyang
     * @return
     */
    public KvOper<T, E> key() {
        this.t.getSelectedModelList().clear();
        this.t.getSelectedModelList().add(new SelectedModel(FieldTypeEnum.KEY, this.field, "key"));
        return new KvOper<T, E>(this.e);
    }

    public T core() {
        return this.t;
    }
}
